<?php
// +----------------------------------------------------------------------
// | ZGUAN [ 致力于帮助更多的中小企业物联网转型 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2024 https://www.zguan.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ZGUAN 并不是自由软件，未经许可不能去掉ZGUAN 相关版权
// +----------------------------------------------------------------------
// | Author: ZGUAN Team <admin@zguan.cn>  0769-82282996  15899929162
// +----------------------------------------------------------------------
namespace app\controller\property;

use app\common\services\CacheService;
use app\common\repositories\property\users\PropertyUsersRepository;

class Index extends Base
{
    /**
     * 登录首页
     * @return string
     * @throws \Exception
     *
     * @author Amos
     * 2024-01-07 13:49
     */
    public function index()
    {
        /** @var PropertyUsersRepository $propertyUsersRepository */
        $propertyUsersRepository = app()->make(PropertyUsersRepository::class);
        $propertyUserInfo = $propertyUsersRepository->getPropertyUserInfo();
        return $this->fetch('index/index', compact('propertyUserInfo'));
    }

    /**
     * 获取侧边菜单目录
     * @return \think\response\Json
     *
     * @author Amos
     * 2024-01-07 13:49
     */
    public function getMenu()
    {
        /** @var PropertyUsersRepository $propertyUsersRepository */
        $propertyUsersRepository = app()->make(PropertyUsersRepository::class);
        $data = $propertyUsersRepository->getMenus();
        return json()->data($data);
    }

    /**
     * 欢迎页
     * @return string
     * @throws \Exception
     *
     * @author Amos
     * 2024-01-07 13:49
     */
    public function welcome()
    {
        $data = [];
        return $this->fetch('index/welcome', [
            'data' => $data
        ]);
    }

    /**
     * 退出登陆
     * @return string|\think\response\Json|\think\response\View
     *
     * @author Amos
     * 2024-01-07 13:48
     */
    public function signOut()
    {
        /** @var PropertyUsersRepository $propertyUsersRepository */
        $propertyUsersRepository = app()->make(PropertyUsersRepository::class);
        $propertyUserInfo = $propertyUsersRepository->getpropertyUserInfo();
        event('property.logout', $propertyUserInfo);
        return $this->success('退出成功');
    }

    /**
     * 清除 缓存
     * @return string|\think\response\Json|\think\response\View
     *
     * @author Amos
     * 2024-01-07 13:45
     */
    public function clearCache()
    {
        CacheService::clearItem($this->request->propertyId);
        return $this->success('缓存清除成功');
    }

}